<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
</head>
<body>
<input id="tel" type="tel" placeholder="手机号">
<button id="getCode">获取验证码</button><br>
<input id="validCode" type="text" placeholder="验证码">
<button id="submit">提交</button>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
    window.onload = function () {
        var telIpt = document.getElementById('tel');
        var getCodeBtn = document.getElementById('getCode');
        var validCode = document.getElementById('validCode');
        var submitBtn = document.getElementById('submit');
        getCodeBtn.onclick = function () {
            var val = telIpt.value;
            var telReg = /^1[35789]\d{9}$/;
            if(telReg.test(val)){
                $.ajax({
                    method:'get',
                    url:'http://localhost:8080/validCodeMsg',
                    data: {
                        phoneNumber: val
                    },
                    success: function (data) {
                        console.log(data);
                    },
                    fail: function (error) {
                        console.log(error);
                    }
                })
            }
        };
        submitBtn.onclick = function () {
            var val = validCode.value;
            // var telReg = /^1[35789]\d{9}$/;
            // if(telReg.test(val)){
                $.ajax({
                    method:'get',
                    url:'http://localhost:8080/valid',
                    data: {
                        validCode: val
                    },
                    success: function (data) {
                        console.log(data);
                    },
                    fail: function (error) {
                        console.log(error);
                    }
                })
            // }
        };
/*


       let a ={ request:
        { method: 'GET',
            url: '/validCodeMsg?phoneNumber=18772510073',
            header:
            { host: 'localhost:8080',
                connection: 'keep-alive',
                accept: '*!/!*',
                origin: 'http://localhost:63342',
                'user-agent':
                'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
                    referer:
                'http://localhost:63342/server/index.html?_ijt=925ric9kokaet190sl4p3p2hrf',
                    'accept-encoding': 'gzip, deflate, br',
                'accept-language': 'zh-CN,zh;q=0.9' } },
            response: { status: 404, message: 'Not Found', header: {} },
            app: { subdomainOffset: 2, proxy: false, env: 'development' },
            originalUrl: '/validCodeMsg?phoneNumber=18772510073',
                req: '<original node req>',
            res: '<original node res>',
            socket: '<original node socket>' };
        let {b} = a.request
        console.log();*/
        // async function testAsync() {
        //     return "hello async";
        // }
        //
        // const result = testAsync();
        // console.log(result);
    }
</script>

</html>
